home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Testing & Debugging / General tools / Report Error 2.0 / StringUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-17  |  2.9 KB  |  86 lines  |  [TEXT/KAHL]

  1. /*================================================================================
  2.     StringUtilities.h
  3.     
  4.     ©1991 Greg Anderson
  5.     greggor@apple.com
  6.     
  7.     FREE DISTRIBUTION
  8.     
  9.     The possessor of this source code may use any portion of
  10.     it for any purpose, and I place no restriction on its
  11.     redistribution.
  12.     
  13.     This .h file provides macros for scanning through strings.
  14.     It is assumed that all strings being scanned are null-terminated
  15.         
  16. ================================================================================*/
  17. #ifndef __STRINGUTILITIES__
  18. #define __STRINGUTILITIES__
  19.  
  20. #ifndef __TYPES__
  21. #include <Types.h>
  22. #endif
  23.  
  24. #define IsDigit(c)            ( ((c) >= '0') && ((c) <= '9') )
  25. #define IsNumeric(c)        ( IsDigit(c) || ((c) == '-') )
  26. #define IsAlpha(c)            ( ( ((c) >= 'A') && ((c) <= 'Z') ) || ( ((c) >= 'a') && ((c) <= 'z') ) )
  27. #define IsAlphaNumeric(c)    ( IsNumeric(c) || IsAlpha(c) )
  28. #define IsWhiteSpace(c)        ( (c) <= ' ' )
  29.  
  30. /*
  31. // Macros:
  32. //
  33. // ToUpper(c)
  34. //
  35. //        Convert 'c' to an uppercase character if it is a lowercase character
  36. //
  37. // SkipToWhiteSpace(p)
  38. //
  39. //        Skip to the next whitespace character (or null)
  40. //
  41. // SkipPastWhitespace(p)
  42. //
  43. //        Skip to the next non-whitespace character (or null)
  44. //
  45. // SkipToSpec(p,spec)
  46. //
  47. //        Skip to the next occurance of the specified character (or null)
  48. //
  49. // SkipToDigit(p)
  50. //
  51. //        Skip to the next numeric digit (or null)
  52. //
  53. // SkipToNextLine(p)
  54. //
  55. //        Like it says:  skip to the beginning of the next line
  56. */
  57. #define ToUpper(c) ( ((c >= 'a') && (c <= 'z')) ? c - 'a' + 'A' : c )
  58. #define SkipToWhitespace( line ) while( *(line) > ' ' ) (line)++
  59. #define SkipPastWhitespace( line ) while( (*(line) <= ' ') && (*(line) != '\r') && (*(line)) ) (line)++
  60. #define SkipToSpec( line, spec ) while( (*(line) != spec) && (*(line)) ) (line)++
  61. #define SkipToDigit( line ) while( ((*(line) < '0') || (*(line) > '9')) && (*(line)) ) (line)++
  62. #define SkipToNextLine( line ) do{ SkipToSpec(line, '\r'); while( (*(line) < ' ') && (*(line)) ) (line)++; } while(false)
  63.  
  64. /*
  65. // Prototypes for stringUtilities.c
  66. */
  67. void                PtoCcpy( char* cstr, Str255 pstr );
  68. void                CtoPcpy(  Str255 pstr, char* cstr );
  69. short                PtoCcmp( Str255 pstr, char* cstr );
  70. pascal void            pstrcpy( Str255 dest, Str255 src );
  71. pascal void            pstrcat( Str255 dest, Str255 src );
  72. short                pstrcmp( unsigned char* a, unsigned char* b );
  73. short                partialstrcmp( register char* s1, register char* s2);
  74. short                ScanNumberInString( char** line );
  75. short                NumberInString( char* line );
  76. void                ScanTextInString( char** line, Str255 pstr, Boolean terminateAtSpace );
  77. void                ScanWordInString( char** line, Str255 pstr );
  78. void                ScanLineInString( char** line, Str255 pstr );
  79.  
  80. void                AddHexCharToString( char* where, unsigned short hexNumber );
  81. void                AddHexByteToString( char* where, unsigned short hexNumber );
  82. void                AddHexShortToString( char* where, unsigned short hexNumber );
  83. void                AddHexLongToString( char* where, unsigned long hexNumber );
  84.  
  85. #endif
  86.